package function;

import model.Author;
import model.GetAuthors;

import java.util.List;

public class Reduce {
    public static void main1(String[] args) {
        List<Author> authors = GetAuthors.getAuthors();
        Integer reduce = authors.stream()
                .distinct()
                .map(author -> author.getAge())
                //第一个参数(0)是result的初始值
                .reduce(0, (result, authorAge) -> result + authorAge);
        System.out.println("Ages:"+reduce);
    }

    public static void main(String[] args) {
        List<Author> authors = GetAuthors.getAuthors();
        Integer MaxAge = authors.stream()
                .distinct()
                .map(author -> author.getAge())
                //第一个参数(0)是result的初始值
                .reduce(Integer.MIN_VALUE, (result, authorAge) ->result>authorAge?result:authorAge);
        System.out.println("Ages:"+MaxAge);
    }
}
